﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>系统用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <button class="layui-btn" lay-filter="sreach" id="btnSure" type="button" onclick="sureChoose()"><i class="layui-icon">&#xe679;</i>确认</button>
                        <button class="layui-btn" lay-filter="sreach" id="btnSure" type="button" onclick="cleanPower()"><i class="layui-icon">&#xe651;</i>取消权限</button>
                    </div>
                        <div class="layui-card-body layui-table-body" id="layui-table-main">
                            <table class="layui-hide" id="list" lay-filter="list"></table>
                        </div>
</div>
            </div>
        </div>
    </div>
</body>

</html>

<script>

    var rCode = "";
    var userCode = "";
    $(function () {
        userCode = decodeURI(getUrlVariable("userCode"));
        rCode = decodeURI(getUrlVariable("roleCode"));
        loadData();
    })

    var currPage = 1;//首先默认值为1，防止出错
    var groupCode="";
    /**
   数据加载
   **/
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var dUrl = "../System/getTableList?dataType=pRole&condition=" + conditon;
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { type: 'radio' }
              , { field: 'groupCode', title: '角色编码', width: 140 }
              , { field: 'groupName', title: '角色名称', width: 130 }
              , { field: 'memo', title: '备 注', width: 250 }
              , { field: 'userName', title: '创建人', width: 90 }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                currPage = curr;
                $.each(res['data'], function (i, json) {
                    if (json["groupCode"]==rCode) {
                        $(".layui-table-view[lay-id='tData'] .layui-table-body tr[data-index =" + i + "] .layui-form-radio").click();
                    }
             
                });
              
            }

            , url: dUrl
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [20, 30, 50]
            , limit: 20 //每页默认显示的数量
            , id: "tData"
            });
            table.on('radio(list)', function (obj) {
                var data = obj.data;
                groupCode=data.groupCode;
 
            });

        });
    }
    /**
    确认选择
    **/
    function sureChoose() {
        if(groupCode==""){
            layer.msg("没有为当前用户选择权限角色");return;
        }
        $.ajax({
            url: "../System/SaveUserRole",
            type: "post",
            data: { userCode: userCode, groupCode: groupCode },
            success: function (data) {
                if (data.Result) {
                    layer.msg("权限设置成功", { icon: 1, time: 500, shade: 0.4 }, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    function cleanPower() {
        $.ajax({
            url: "../System/cleanUserRole",
            type: "post",
            data: { userCode: userCode},
            success: function (data) {
                if (data.Result) {
                    layer.msg("权限清除成功", { icon: 1, time: 500, shade: 0.4 }, function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
</script>